
logit <- function(p){
  if (!is.numeric(p) || any(p <= 0 | p >= 1)) {
    stop("p must be in [0,1)")
  }
  
  return(log(p) - log(1-p))
}

print(log(exp(1)))

inv_logit <- function(p){
  
  exp(p) / (1 + exp(x))
}

print(logit(0.99))


p <- seq(0.001, 0.999, length=100)
plot(p, logit(p), type='l', lwd=2, col='blue',
     xlab='p', ylab='logit(p)', main='Logit function: log(p) - log(1-p)')
abline(h=0, lty=2)
